// pages/admin/admin.js
Page({
  data: {
    uploading: false,
    result: '',
    error: ''
  },

  onLoad: function(options) {
    // 页面加载时的逻辑
  },

  // 上传小动物数据到云数据库
  uploadVillagersData: function() {
    this.setData({
      uploading: true,
      result: '',
      error: ''
    });

    wx.cloud.callFunction({
      name: 'uploadVillagersData',
      data: {
        uploadImages: true // 设置为true表示也上传图片到云存储
      },
      success: res => {
        console.log('上传结果:', res);
        this.setData({
          result: JSON.stringify(res.result, null, 2),
          uploading: false
        });
      },
      fail: err => {
        console.error('调用云函数失败:', err);
        this.setData({
          error: JSON.stringify(err, null, 2),
          uploading: false
        });
      }
    });
  }
})